home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / misc / football / exec / cupschedulenextround.rexx < prev    next >
OS/2 REXX Batch file  |  1999-11-29  |  43KB  |  1,355 lines

  1. /* ***********************************************************************
  2.  
  3.    CUP NEXT ROUND SCHEDULER PROGRAM FOR FOOTBALL REXX SUITE
  4.   ----------------------------------------------------------
  5.                    Copyright  Mark Naughton 1997
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  1.0       091297   Started. Has been planned for 3 weeks.
  11.            131297   After a two day break, have completed the code. Now
  12.                     for the testing... Searching out those problems...
  13.            141297   Code works alright up to the Final where it failed due
  14.                     to 'datafile2' being used instead of 'datafile'.
  15.                     Amended Final code to handle replays. One Cup has been
  16.                     run through and now works. Three more to go.
  17.            151297   Improved round names when matches are displayed.
  18.                     Added code to change current round, after the final
  19.                     is played to FINISHED so you will still be able to
  20.                     view results and run scripts on the Cup.
  21.            161297   Amended bettername so it handled replays in early
  22.                     rounds. Undummied code to swap teams around when a
  23.                     replay is needed - Home:=Away and Away:=Home.
  24.                     Third place doesn't get setup - oh dear.
  25.            171297   Noticed that the teams for third place aren't stored
  26.                     - amended. Third also didn't store losing teams in
  27.                     working file. Winning teams are now stored with "#"
  28.                     and the losing ones are deleted when Third has been
  29.                     played.
  30.            181297   Fixed bug where teams for Final Replay where picked
  31.                     up from the teams in Third Place Play-Off. Added
  32.                     cosmetic changes to reports. Its working so all
  33.                     debug information will be taken out.
  34.            070698   Added code for manually scheduling.
  35.            290898   With the addition of two-legged matches and away goals
  36.                     this program was going to be the beast to amend.
  37.                     Started planning the amendments.
  38.            030998   Nearly five days later, the amendments have been made.
  39.                     Now for the testing...
  40.            050998   What a nightmare. Testing is complete and many little
  41.                     bugs were found but not documented. Take it from me,
  42.                     it works..(kind of).
  43.            100998   Made several improvements during the course of finding
  44.                     the bug (found in CupUpdateMatches.rexx) which missed
  45.                     data lines during recreation of '.scf' file.
  46.            120998   Amended winner check to handle away goals when there
  47.                     is a different score after extra time to that at full
  48.                     time.
  49.            250899   Added error msg to file checks.
  50.  1.1       050999   Converted to use locale. Some error messages, before
  51.                     reading the locale, will still be in English.
  52.                     English language still needs to appear in the datafiles
  53.                     for processing by Football. Tidied some displays.
  54.            200999   Now reads main locale settings file - missed various
  55.                     settings.
  56.  
  57. **************************************************************************
  58.  
  59. Procedure           (Where Third is mentioned, it only gets the data
  60. ---------                                     if the option has been set)
  61.  
  62. 1. Check files exist.
  63. 2. Read '.cf' file and get settings.
  64. 3. Read '.cfrw' file. Store and get current round settings.
  65. 4. Read matches from '.scf' file.
  66. 5. Check if any of these matches haven't been played - if they haven't then
  67.    give error and exit.
  68. 6. If current round is Third, set round to Final, adjust teams, write back
  69.    to '.cfrw' file, give message and exit.
  70. 7. If at the end of the number of rounds, read Final and Third matches.
  71. 8. If Third is set, get the winner/loser of the Third Place Play-Off.
  72. 9. Search for the Final, find winner. If replay, store after checking its
  73.    not already been stored.
  74. 10.If not a replay, write IGNORE in replay array.
  75. 11.If replays exist, adjust roundname.
  76. 12.Go through the replays, setting them to not played.
  77. 13.Write '.cfrw' file back to itself.
  78. 14.Append replays back to '.scf' file and give message and exit.
  79. 15.If no replays exist (linked to No.11), if history (if set) file doesn't
  80.    exist, then create it.
  81. 16.Append winner/loser and if set, third and fourth place.
  82. 17.Change round to 'Finished'. Write '.cfrw' file. Give end message and
  83.    exit.
  84. 18.If not at the end of the number of rounds (linked to No.7), search
  85.    matches, finding winners/losers and replays (if applicable).
  86. 19.If replays exist, search '.cfrw' file, putting '#' in front of teams
  87.    not in replays.
  88. 20.Adjust roundname.
  89. 21.Write not played and swap teams, checking replays aren't ignored and
  90.    if they are, decrement the count.
  91. 22.If no replays, get teams minus the '#'. Write '.cfrw' file.
  92. 23.If replays append to '.scf' file, give message and exit.
  93. 24.If no replays (linked to No.19) exist, read '.cfrw' file again, getting
  94.    the settings.
  95. 25.Read matches for current round.
  96. 26.Search matches, storing winners/losers. Update '.cfrw' settings then
  97.    rewrite '.cfrw' file.
  98. 27.If Third, dummy out finalists.
  99. 28.If Semi-Finals, write Third (if set) and Final matches, give message
  100.    and exit.
  101. 29.Random match generator - get number and store.
  102. 30.Append matches to '.scf' file, writing home and away teams according to
  103.    the randomly generated array.
  104. 31.Give message for next round and exit.
  105. 32.Routine 'whosthewinr' - depending on the settings for each round
  106.    (Extra Time and Penalties), decide who the winner and loser are, and
  107.    return the winner on the left side of '*****'. Return '#####' if its
  108.    the 1st leg of Two.
  109. 33.Routine 'bettername' - using the current round name, create a more
  110.    useful name, ie. "Quart" becomes "Quarter Finals" and "1st Replays"
  111.    becomes "1st Round Replays", etc.
  112.  
  113. ************************************************************************** */
  114. PARSE ARG league_stuff
  115.  
  116. version      = 1
  117. input_file   = '.cf'
  118. input2_file  = '.scf'
  119. input3_file  = '.cfrw'
  120. input4_file  = '.cfh'
  121. output3_file = '.temp'
  122. indicator    = 'RAM:MatchesToBeDone'
  123. title        = '*CUP_TITLE='
  124. thirdpl      = '*CUP_THIRD='
  125. rounddef     = '*CUP_RNDDEF='
  126. currond      = '*CUP_ROND='
  127. currrondn    = '*CUP_CRDN='
  128. roundddef    = '*CUP_RDEF='
  129. cuphistory   = '*CUP_HISTORY='
  130. thirdpl      = '*CUP_THIRD='
  131. teams_cnt    = '*CUP_TCNT='
  132. awaygs       = '*CUP_AWAYG='
  133. schedtype    = '*CUP_SCHEDULE='
  134. pkversion    = '*  Version='
  135. matches.     = '???'
  136. separator    = '*'
  137. teams.       = '???'
  138. rnds.        = '???'
  139. lines.       = '???'
  140. replays.     = '???'
  141. working.     = '???'
  142. losing.      = '???'
  143. repct        = 0
  144. repno.       = '???'
  145. tcount       = 0
  146. ttc          = 0
  147. rndcnt       = 0
  148. linesct      = 0
  149. league_file  = "Data/"league_stuff
  150. curnd        = ''
  151. curndn       = 0
  152. not_played   = "__   __"
  153.  
  154.  
  155. if open(datafile,"Data/Football.locale",'r') then do
  156.    line = readln(datafile)
  157.    locdir = strip(line)
  158.    close(datafile)
  159. end
  160. else do
  161.    say
  162.    say "ERROR :    (CupScheduleNextRound)"
  163.    say
  164.    say "Cannot read 'Data/Football.locale' for the locale settings."
  165.    exit
  166. end
  167.  
  168. dcupdir = locdir"Football.locale_cup"
  169. dfordir = locdir"Football.locale_data"
  170. locdir = locdir"Exec/CupScheduleNextRound.data"
  171.  
  172. if open(datafile,"ENV:FootballRXPath",'r') then do
  173.    line = readln(datafile)
  174.    rxdir = strip(line)
  175.    close(datafile)
  176. end
  177. else
  178.    rxdir = "SYS:Rexxc/"
  179.  
  180. if exists(locdir) > 0 then do
  181.   address command rxdir'rx 'locdir
  182.   VarCount = getclip('VarCount')
  183.   do i = 1 to VarCount
  184.     interpret getclip('var.'i)
  185.   end
  186. end
  187. else do
  188.    say
  189.    say "ERROR :    (CupScheduleNextRound)"
  190.    say
  191.    say "Cannot find '"locdir"' to read locale settings."
  192.    exit
  193. end
  194.  
  195. if exists(dcupdir) > 0 then do
  196.   address command rxdir'rx 'dcupdir
  197.   VarCount = getclip('VarCount')
  198.   do i = 1 to VarCount
  199.     interpret getclip('var.'i)
  200.   end
  201. end
  202. else do
  203.    say
  204.    say "ERROR :    (CupScheduleNextRound)"
  205.    say
  206.    say "Cannot find '"dcupdir"' to read cup locale settings."
  207.    exit
  208. end
  209.  
  210. if exists(dfordir) > 0 then do
  211.   address command rxdir'rx 'dfordir
  212.   VarCount = getclip('VarCount')
  213.   do i = 1 to VarCount
  214.     interpret getclip('var.'i)
  215.   end
  216. end
  217. else do
  218.    say
  219.    say "ERROR :    (CupScheduleNextRound)"
  220.    say
  221.    say "Cannot find '"dfordir"' to read locale settings."
  222.    exit
  223. end
  224.  
  225. if exists(league_file||input_file) = 0 then do
  226.    say
  227.    say csnr_error
  228.    say
  229.    say csnr_t1"'"league_file||input_file"'."
  230.    exit
  231. end
  232.  
  233. if exists(league_file||input2_file) = 0 then do
  234.    say
  235.    say csnr_error
  236.    say
  237.    say csnr_t1"'"league_file||input2_file"'."
  238.    exit
  239. end
  240.  
  241. if exists(league_file||input3_file) = 0 then do
  242.    say
  243.    say csnr_error
  244.    say
  245.    say csnr_t1"'"league_file||input3_file"'."
  246.    exit
  247. end
  248.  
  249. if open(datafile,league_file || input_file,'r') then do
  250.    do while ~eof(datafile)
  251.       line = readln(datafile)
  252.       if pos(title,line) > 0 then        cupname = delstr(line,1,11)
  253.       if pos(cuphistory,line) > 0 then   cuph    = delstr(line,1,13)
  254.       if pos(thirdpl,line) > 0 then      third   = delstr(line,1,11)
  255.       if pos(awaygs,line) > 0 then       awaygls = delstr(line,1,11)
  256.       if pos(schedtype,line) > 0 then    scht    = delstr(line,1,14)
  257.       if pos(rounddef,line) > 0 then do
  258.          rndcnt = rndcnt + 1
  259.          rnds.rndcnt = delstr(line,1,12)
  260.       end
  261.    end
  262.    close(datafile)
  263. end
  264. else do
  265.    say
  266.    say csnr_error
  267.    say
  268.    say csnr_t2"'"league_file || input_file"'."
  269.    exit
  270. end
  271.  
  272. if open(datafile,league_file || input3_file,'r') then do
  273.    do while ~eof(datafile)
  274.       line = readln(datafile)
  275.       linesct = linesct + 1
  276.       lines.linesct = line
  277.       if pos(currond,line)   > 0 then crond  = strip(substr(line,11,2))
  278.       if pos(roundddef,line) > 0 then tcrondn= strip(substr(line,11,5))
  279.       if pos(currrondn,line) > 0 then do
  280.          crondn = strip(substr(line,11,30))
  281.          tleg_no = 0
  282.          if pos("1 Leg",line) > 0 then tleg_no = 1
  283.          if pos("2 Legs",line) > 0 then tleg_no = 2
  284.       end
  285.    end
  286.    close(datafile)
  287. end
  288. else do
  289.    say
  290.    say csnr_error
  291.    say
  292.    say csnr_t2"'"league_file || input3_file"'."
  293.    exit
  294. end
  295.  
  296. leg_number = 0
  297. if pos("Leg",crondn) > 0 then do
  298.    if pos("2 Legs",crondn) > 0 then
  299.       leg_number = 2
  300.    else
  301.       leg_number = 1
  302. end
  303.                     /* this can be here or later....decide! */
  304. mkr = 0
  305. ttc = 0
  306. if open(datafile,league_file || input2_file,'r') then do
  307.    do while ~eof(datafile)
  308.       line = readln(datafile)
  309.       if pos("*Round="strip(tcrondn),line) > 0 & mkr = 0 then do
  310.          if pos("Leg",line) > 0 then do
  311.             if tleg_no = 1 & pos("1 Leg",line) > 0 then mkr = 1
  312.             if tleg_no = 2 & pos("2 Legs",line) > 0 then mkr = 1
  313.          end
  314.          else
  315.             mkr = 1
  316.       end
  317.       if mkr = 1 then do
  318.          ttc = ttc + 1
  319.          matches.ttc = line
  320.       end
  321.    end
  322.    close(datafile)
  323. end
  324. else do
  325.    say
  326.    say csnr_error
  327.    say
  328.    say csnr_t2"'"league_file || input2_file"'."
  329.    exit
  330. end
  331.  
  332. do i=1 to ttc
  333.    if pos(not_played,matches.i) > 0 & pos("#",matches.i) = 0 & pos("Third",crondn) = 0 then do
  334.       say
  335.       say center("'"cupname"'",78)
  336.       say "-------------------------------------------------------------------------------"
  337.       say
  338.       say csnr_t3
  339.       say
  340.       say csnr_t4
  341.       say csnr_t5
  342.       say
  343.       say "-------------------------------------------------------------------------------"
  344.       exit
  345.    end
  346. end
  347.  
  348. if pos("Third",crondn) > 0 then do
  349.    do i=1 to linesct
  350.       if pos(currond,lines.i)   > 0 then lines.i=currond||rndcnt
  351.       if pos(currrondn,lines.i) > 0 then do
  352.          if pos("Leg",rnds.rndcnt) > 0 then do
  353.             if pos("2 Legs",crondn) > 0 then
  354.                lines.i=currrondn||"Final            2 Legs"
  355.             else
  356.                lines.i=currrondn||"Final            1 Leg"
  357.          end
  358.          else
  359.            lines.i=currrondn||"Final"
  360.       end
  361.       if pos(roundddef,lines.i) > 0 then lines.i=roundddef||rnds.rndcnt
  362.       if pos(separator,lines.i) = 0 then do
  363.          if pos("#",lines.i) = 0 then
  364.             lines.i = "-DELETED-"
  365.          else do
  366.             parse var lines.i "#"teamname
  367.             lines.i = teamname
  368.          end
  369.       end
  370.    end
  371.    if open(datafile,league_file || input3_file,'w') then do
  372.       do p=1 to i
  373.          if p = i then
  374.             writech(datafile,lines.p)
  375.          else
  376.             writeln(datafile,lines.p)
  377.       end
  378.       close(datafile)
  379.    end
  380.    else do
  381.       say
  382.       say csnr_error
  383.       say
  384.       say csnr_t2"'"league_file || input3_file"'"csnr_t6
  385.       exit
  386.    end
  387.    leg_do = "Blank"
  388.    if pos("2 Legs",rnds.rndcnt) > 0 then
  389.       leg_do = "1 Leg"
  390.    say
  391.    say center("'"cupname"'",78)
  392.    say "-------------------------------------------------------------------------------"
  393.    say
  394.    say cs_t28" : "bettername("Final",leg_do)
  395.    say
  396.    do i=1 to ttc
  397.       if pos("*Round=Final",matches.i) > 0 then do
  398.          g = i + 2
  399.          say matches.g
  400.          leave
  401.       end
  402.    end
  403.    say
  404.    say "-------------------------------------------------------------------------------"
  405.    exit
  406. end
  407.  
  408. if crond = rndcnt then do
  409.    if pos("YES",third) > 0 then
  410.       temprond = "Third"
  411.    else
  412.       temprond = "Final"
  413.    mkr = 0
  414.    ttc = 0
  415.    matchcnt = 0
  416.    if open(datafile,league_file || input2_file,'r') then do
  417.       do while ~eof(datafile)
  418.          line = readln(datafile)
  419.          if pos("*Round="strip(temprond),line) then
  420.             mkr = 1
  421.          if mkr = 1 then do
  422.             ttc = ttc + 1
  423.             matches.ttc = line
  424.          end
  425.          if pos(separator,line) = 0 & pos("#",line) = 0 & line~='' then
  426.             matchcnt = matchcnt + 1
  427.       end
  428.       close(datafile)
  429.    end
  430.    else do
  431.       say
  432.       say csnr_error
  433.       say
  434.       say csnr_t2"'"league_file || input2_file"'."
  435.       exit
  436.    end
  437.  
  438.    if pos("YES",third) > 0 then do
  439.       where = crond - 1
  440.       ermm  = substr(rnds.where,1,5)
  441.       posit = 0
  442.       do i=1 to ttc
  443.          if pos("Third",matches.i) > 0 then do
  444.             posit = i + 2
  445.             leave
  446.          end
  447.       end
  448.       thirdstrng = whosthewinr(posit,rnds.where,ermm,0,"NO")
  449.    end
  450.    mkr = 0
  451.    if pos("Leg",crondn) > 0 then do
  452.       if pos("2 Legs",crondn) > 0 then
  453.          leg_number = 2
  454.       else
  455.          leg_number = 1
  456.    end
  457.    else
  458.       leg_number = 0
  459.    do i=1 to ttc
  460.       if pos("Final",matches.i) > 0 then
  461.          mkr = 1
  462.       if pos('*',matches.i) = 0 & pos('#',matches.i) = 0 & matches.i~='' & mkr = 1 then do
  463.          match_1f = i
  464.          strng = whosthewinr(i,rnds.crond,crondn,leg_number,awaygls)
  465.          if pos("REPLAY",strng) > 0 then do
  466.             repno.repct = i
  467.             teama = strip(substr(matches.i,1,30))
  468.             teamb = strip(substr(matches.i,41,30))
  469.             do k=1 to repct
  470.                if pos(teama,replays.k) > 0 & pos(teamb,replays.k) > 0 & repno.k~=i then do
  471.                   replays.k = "IGNORE"
  472.                end
  473.             end
  474.          end
  475.          if pos("NOP",strng) = 0 & pos("REPLAY",strng) = 0 then do
  476.             teama = strip(substr(matches.i,1,30))
  477.             teamb = strip(substr(matches.i,41,30))
  478.             do k=1 to repct
  479.                if pos(teama,replays.k) > 0 & pos(teamb,replays.k) > 0 then do
  480.                   replays.k = "IGNORE"
  481.                end
  482.             end
  483.          end
  484.       end
  485.    end
  486.    if repct > 0 then do
  487.       do j=1 to linesct
  488.          if pos(currrondn,lines.j) > 0 & pos("Replay",lines.j) = 0 then
  489.             lines.j=lines.j||" Replay"
  490.       end
  491.       trepct = repct
  492.       do i=1 to repct
  493.          if pos("IGNORE",replays.i) = 0 then
  494.             replays.i = overlay(not_played,replays.i,32)
  495.          else
  496.             trepct = trepct - 1
  497.       end
  498.       if trepct = 0 then repct = 0
  499.       if open(datafile,league_file || input3_file,'w') then do
  500.          do p=1 to linesct
  501.             if p = linesct then
  502.                writech(datafile,lines.p)
  503.             else
  504.                writeln(datafile,lines.p)
  505.          end
  506.          close(datafile)
  507.       end
  508.       else do
  509.          say
  510.          say csnr_error
  511.          say
  512.          say csnr_t2"'"league_file || input3_file"'"csnr_t6
  513.          exit
  514.       end
  515.       if repct > 0 then do
  516.          if open(datafile,league_file || input2_file,'a') then do
  517.             writeln(datafile,"*Round="tcrondn" Replay")
  518.             writeln(datafile,"*")
  519.             do p=1 to repct
  520.                if pos("IGNORE",replays.p) = 0 then
  521.                   writeln(datafile,replays.p)
  522.             end
  523.             writeln(datafile,"*")
  524.             close(datafile)
  525.          end
  526.          else do
  527.             say
  528.             say csnr_error
  529.             say
  530.             say csnr_t2"'"league_file || input2_file"'"csnr_t7
  531.             exit
  532.          end
  533.          say
  534.          say center("'"cupname"'",78)
  535.          say "-------------------------------------------------------------------------------"
  536.          say
  537.          say cs_t28" : "bettername(word(crondn,1)" Replay ","Blank")
  538.          say
  539.          do i=1 to repct
  540.             if pos("IGNORE",replays.i) = 0 then
  541.                say replays.i
  542.          end
  543.          say
  544.          say "-------------------------------------------------------------------------------"
  545.          exit
  546.       end
  547.    end
  548.    if repct = 0 then do
  549.       winning = strng
  550.       if pos("#####",winning) > 0 then do
  551.          parse var winning l1teamh "#####" l1teama
  552.          do j=1 to linesct
  553.             if pos(currrondn,lines.j) > 0 then
  554.                lines.j=currrondn||word(tcrondn,1)"   2 Legs"
  555.          end
  556.          if open(datafile,league_file || input3_file,'w') then do
  557.             do p=1 to linesct
  558.                if p = linesct then
  559.                   writech(datafile,lines.p)
  560.                else
  561.                   writeln(datafile,lines.p)
  562.             end
  563.             close(datafile)
  564.          end
  565.          else do
  566.             say
  567.             say csnr_error
  568.             say
  569.             say csnr_t2"'"league_file || input3_file"'"csnr_t6
  570.             exit
  571.          end
  572.          if open(datafile,league_file || input2_file,'a') then do
  573.             writeln(datafile,"*Round="word(tcrondn,1)"   2 Legs")
  574.             writeln(datafile,"*")
  575.             writeln(datafile,left(l1teama,30," ")" __   __ " l1teamh)
  576.             writeln(datafile,left("#1st Leg",30," ")" "right(strip(substr(matches.match_1f,37,2)),2)"   "right(strip(substr(matches.match_1f,32,2)),2))
  577.             writeln(datafile,"*")
  578.             close(datafile)
  579.          end
  580.          else do
  581.             say
  582.             say csnr_error
  583.             say
  584.             say csnr_t2"'"league_file || input2_file"'"csnr_t7
  585.             exit
  586.          end
  587.          say
  588.          say center("'"cupname"'",78)
  589.          say "-------------------------------------------------------------------------------"
  590.          say
  591.          say cs_t28" : "bettername(word(crondn,1),"2 Legs")
  592.          say
  593.          s1 = strip(substr(matches.match_1f,37,2))
  594.          s2 = strip(substr(matches.match_1f,32,2))
  595.          say left(l1teama,30," ")" ("s1")  "txt_versus"  ("s2")   "l1teamh
  596.          say
  597.          say "-------------------------------------------------------------------------------"
  598.          exit
  599.       end
  600.       parse var winning winner"*****"loser
  601.       parse var thirdstrng thirdplace"*****"fourthplace
  602.  
  603.       if pos("YES",cuph) > 0 then do
  604.          if exists(league_file||input4_file) = 0 then do
  605.             if open(datafile,league_file||input4_file,'w') then do
  606.                writeln(datafile,"*")
  607.                writeln(datafile,"** History for '"cupname"'")
  608.                writeln(datafile,"*")
  609.                close(datafile)
  610.             end
  611.             else do
  612.                say
  613.                say csnr_error
  614.                say
  615.                say csnr_t8"'"league_file||input4_file"'."
  616.                exit
  617.             end
  618.          end
  619.  
  620.          if open(datafile,league_file||input4_file,'a') then do
  621.             writeln(datafile,"*WINNER="winner)
  622.             writeln(datafile,"*RUNNERUP="loser)
  623.             if pos("YES",third) > 0 then do
  624.                writeln(datafile,"*THIRD="thirdplace)
  625.                writeln(datafile,"*FOURTH="fourthplace)
  626.             end
  627.             writeln(datafile,"*")
  628.             close(datafile)
  629.          end
  630.          else do
  631.             say
  632.             say csnr_error
  633.             say
  634.             say csnr_t9"'"league_file||input4_file"'."
  635.             exit
  636.          end
  637.       end
  638.                             /* write FINISHED to Working file so it can be read by Football */
  639.                             /* but no scores will be able to be updated.                    */
  640.       do i=1 to linesct
  641.          if pos(currrondn,lines.i) > 0 then lines.i=currrondn||"Finished"
  642.       end
  643.       if open(datafile,league_file || input3_file,'w') then do
  644.          do p=1 to i
  645.             if p = i then
  646.                writech(datafile,lines.p)
  647.             else
  648.                writeln(datafile,lines.p)
  649.          end
  650.          close(datafile)
  651.       end
  652.       else do
  653.          say
  654.          say csnr_error
  655.          say
  656.          say csnr_t2"'"league_file || input3_file"'"csnr_t6
  657.          exit
  658.       end
  659.  
  660.       say
  661.       say center("'"cupname"'",78)
  662.       say "-------------------------------------------------------------------------------"
  663.       say
  664.       say csnr_t10" "matchcnt", "
  665.       say csnr_t11
  666.       say
  667.       say
  668.       say "                        "csnr_t12"    "upper(winner)
  669.       say
  670.       say "                        "csnr_t13"    "loser
  671.       if pos("YES",third) > 0 then do
  672.          say "                        "csnr_t14"    "thirdplace
  673.          say "                        "csnr_t15"    "fourthplace
  674.       end
  675.       say
  676.       say "-------------------------------------------------------------------------------"
  677.       exit
  678.    end
  679. end
  680. if crond ~= rndcnt then do
  681.    do i=1 to ttc
  682.       if pos('*',matches.i) = 0 & pos('#',matches.i) = 0 & matches.i~='' then do
  683.          strng = whosthewinr(i,rnds.crond,crondn,leg_number,awaygls)
  684.          if pos("REPLAY",strng) > 0 then do
  685.             repno.repct = i
  686.             teama = strip(substr(matches.i,1,30))
  687.             teamb = strip(substr(matches.i,41,30))
  688.             do k=1 to repct
  689.                if pos(teama,replays.k) > 0 & pos(teamb,replays.k) > 0 & repno.k~=i then do
  690.                   replays.k = "IGNORE"
  691.                end
  692.             end
  693.          end
  694.          if pos("NOP",strng) = 0 & pos("REPLAY",strng) = 0 then do
  695.             teama = strip(substr(matches.i,1,30))
  696.             teamb = strip(substr(matches.i,41,30))
  697.             do k=1 to repct
  698.                if pos(teama,replays.k) > 0 & pos(teamb,replays.k) > 0 then do
  699.                   replays.k = "IGNORE"
  700.                end
  701.             end
  702.          end
  703.       end
  704.    end
  705.  
  706.    if repct > 0 then do
  707.       do j=1 to linesct
  708.          if pos(separator,lines.j) = 0 & pos("#",lines.j) = 0 then do
  709.             willhe = 0
  710.             do p=1 to repct
  711.                if pos(strip(lines.j),replays.p) > 0 then
  712.                   willhe = 1
  713.             end
  714.             if willhe = 0 then
  715.                lines.j = insert("#",lines.j,0)
  716.          end
  717.       end
  718.       do j=1 to linesct
  719.          if pos(currrondn,lines.j) > 0 & pos("Replay",lines.j) = 0 then
  720.             lines.j=lines.j||" Replays"
  721.       end
  722.       trepct = repct
  723.       do i=1 to repct
  724.          if pos("IGNORE",replays.i) = 0 then do
  725.             replays.i = overlay(not_played,replays.i,32)
  726.             teama = strip(substr(replays.i,1,30))    /* this code swaps the teams round for replays */
  727.             teamb = strip(substr(replays.i,41,30))
  728.             replays.i = overlay(teama,replays.i,41,30)
  729.             replays.i = overlay(teamb,replays.i,1,30)
  730.          end
  731.          else
  732.             trepct = trepct - 1
  733.       end
  734.       if trepct = 0 then repct = 0
  735.       if repct = 0 then do
  736.          do p=1 to linesct
  737.             if pos("#",lines.p) > 0 then
  738.                lines.p = delstr(lines.p,1,1)
  739.          end
  740.       end
  741.       if open(datafile,league_file || input3_file,'w') then do
  742.          do p=1 to linesct
  743.             if p = linesct then
  744.                writech(datafile,lines.p)
  745.             else
  746.                writeln(datafile,lines.p)
  747.          end
  748.          close(datafile)
  749.       end
  750.       else do
  751.          say
  752.          say csnr_error
  753.          say
  754.          say csnr_t2"'"league_file || input3_file"'"csnr_t6
  755.          exit
  756.       end
  757.       if repct > 0 then do
  758.          if open(datafile,league_file || input2_file,'a') then do
  759.             writeln(datafile,"*Round="tcrondn" Replays")
  760.             writeln(datafile,"*")
  761.             do p=1 to repct
  762.                if pos("IGNORE",replays.p) = 0 then
  763.                   writeln(datafile,replays.p)
  764.             end
  765.             writeln(datafile,"*")
  766.             close(datafile)
  767.          end
  768.          else do
  769.             say
  770.             say csnr_error
  771.             say
  772.             say csnr_t2"'"league_file || input2_file"'"csnr_t6
  773.             exit
  774.          end
  775.          say
  776.          say center("'"cupname"'",78)
  777.          say "-------------------------------------------------------------------------------"
  778.          say
  779.          say cs_t28" : "bettername(crondn,"Blank")
  780.          say
  781.          say csnr_t16
  782.          say
  783.          do i=1 to repct
  784.             if pos("IGNORE",replays.i) = 0 then do
  785.                parse var replays.i trep1 "__   __" trep2
  786.                say left(strip(trep1),30," ")||txt_versus||strip(trep2)
  787.             end
  788.          end
  789.          say
  790.          say "-------------------------------------------------------------------------------"
  791.          exit
  792.       end
  793.    end
  794.    if repct = 0 then do
  795.       linesct = 0
  796.       if open(datafile,league_file || input3_file,'r') then do
  797.          do while ~eof(datafile)
  798.             line = readln(datafile)
  799.             linesct = linesct + 1
  800.             lines.linesct = line
  801.             if pos(currond,line)   > 0 then crond  = strip(substr(line,11,2))
  802.             if pos(roundddef,line) > 0 then tcrondn= strip(substr(line,11,5))
  803.             if pos(currrondn,line) > 0 then do
  804.                crondn = strip(substr(line,11,30))
  805.                tleg_no = 0
  806.                if pos("1 Leg",line) > 0 then tleg_no = 1
  807.                if pos("2 Legs",line) > 0 then tleg_no = 2
  808.             end
  809.          end
  810.          close(datafile)
  811.       end
  812.       else do
  813.          say
  814.          say csnr_error
  815.          say
  816.          say csnr_t2"'"league_file || input3_file"'."
  817.          exit
  818.       end
  819.       ttc = 0
  820.       mkr = 0
  821.       if open(datafile,league_file || input2_file,'r') then do
  822.          do while ~eof(datafile)
  823.             line = readln(datafile)
  824.             if pos("*Round="strip(tcrondn),line) > 0 & mkr = 0 then do
  825.                if pos("Leg",line) > 0 then do
  826.                   if tleg_no = 1 & pos("1 Leg",line) > 0 then mkr = 1
  827.                   if tleg_no = 2 & pos("2 Legs",line) > 0 then mkr = 1
  828.                end
  829.                else
  830.                   mkr = 1
  831.             end
  832.             if mkr = 1 then do
  833.                ttc = ttc + 1
  834.                matches.ttc = line
  835.             end
  836.          end
  837.          close(datafile)
  838.       end
  839.       else do
  840.          say
  841.          say csnr_error
  842.          say
  843.          say csnr_t2"'"league_file || input2_file"'."
  844.          exit
  845.       end
  846.       winct  = 0
  847.       losct  = 0
  848.       do i=1 to ttc
  849.          if pos("*Round",matches.i) > 0 then
  850.             parse var matches.i "*Round="crondn
  851.          if pos(separator,matches.i) = 0 & pos("#",matches.i) = 0 & matches.i~='' then do
  852.             strng = whosthewinr(i,rnds.crond,crondn,tleg_no,awaygls)
  853.             if pos("REPLAY",strng) = 0 & pos("NOP",strng) = 0 then do
  854.                if pos("#####",strng) = 0 then do
  855.                   parse var strng tempa "*****" tempb
  856.                   mn = 0
  857.                   do k=1 to winct
  858.                      if pos(strip(tempa),working.k) > 0 then mn=1
  859.                   end
  860.                   if mn = 0 then do
  861.                      winct = winct + 1
  862.                      working.winct = strip(tempa)
  863.                   end
  864.                   mn = 0
  865.                   do k=1 to losct
  866.                      if pos(strip(tempb),losing.k) > 0 then mn=1
  867.                   end
  868.                   if mn = 0 then do
  869.                      losct = losct + 1
  870.                      losing.losct = strip(tempb)
  871.                   end
  872.                end
  873.                if pos("#####",strng) > 0 then do
  874.                   parse var strng tempa "#####" tempb
  875.                   winct = winct + 1
  876.                   working.winct = strip(tempb)
  877.                   winct = winct + 1
  878.                   working.winct = strip(tempa)
  879.                   losct = losct + 1
  880.                   losing.losct  = matches.i
  881.                end
  882.             end
  883.             strng = ""
  884.          end
  885.       end
  886.       if tleg_no = 1 then do
  887.          do j=1 to linesct
  888.             if pos(currrondn,lines.j) > 0 then
  889.                lines.j=currrondn||word(tcrondn,1)"   2 Legs"
  890.          end
  891.          if open(datafile,league_file || input3_file,'w') then do
  892.             do p=1 to linesct
  893.                if p = linesct then
  894.                   writech(datafile,lines.p)
  895.                else
  896.                   writeln(datafile,lines.p)
  897.             end
  898.             close(datafile)
  899.          end
  900.          else do
  901.             say
  902.             say csnr_error
  903.             say
  904.             say csnr_t2"'"league_file || input3_file"'"csnr_t6
  905.             exit
  906.          end
  907.          if open(datafile,league_file || input2_file,'a') then do
  908.             writeln(datafile,"*Round="word(tcrondn,1)"   2 Legs")
  909.             writeln(datafile,"*")
  910.             lg1ct = 0
  911.             do i=1 to winct by 2
  912.                l = i + 1
  913.                writeln(datafile,left(working.i,30," ")" __   __ " working.l)
  914.                lg1ct = lg1ct + 1
  915.                leg1match = losing.lg1ct
  916.                leg1match = overlay(" ",leg1match,1,30)
  917.                leg1match = overlay(" ",leg1match,41,30)
  918.                leg1match = overlay("#1st Leg",leg1match,1)
  919.                score1    = substr(leg1match,32,2)
  920.                score2    = substr(leg1match,37,2)
  921.                leg1match = overlay(score2,leg1match,32,2)
  922.                leg1match = overlay(score1,leg1match,37,2)
  923.                writeln(datafile,leg1match)
  924.             end
  925.             writeln(datafile,"*")
  926.             close(datafile)
  927.          end
  928.          else do
  929.             say
  930.             say csnr_error
  931.             say
  932.             say csnr_t2"'"league_file || input2_file"'"csnr_t7
  933.             exit
  934.          end
  935.          say
  936.          say center("'"cupname"'",78)
  937.          say "-------------------------------------------------------------------------------"
  938.          say
  939.          say cs_t28" : "bettername(word(crondn,1),"2 Legs")
  940.          say
  941.          lg1ct = 0
  942.          do i=1 to winct by 2
  943.             l = i + 1
  944.             lg1ct = lg1ct + 1
  945.             leg1match = losing.lg1ct
  946.             s1 = strip(substr(losing.lg1ct,37,2))
  947.             s2 = strip(substr(losing.lg1ct,32,2))
  948.             say left(working.i,30," ")" ("s1")  "txt_versus"  ("s2")   "working.l
  949.          end
  950.          say
  951.          say "-------------------------------------------------------------------------------"
  952.          exit
  953.       end
  954.  
  955.       crond = crond + 1
  956.       if pos("Third",crond) > 0 then
  957.          winct = winct + losct
  958.       do j=1 to linesct
  959.          if pos(roundddef,lines.j) > 0 then lines.j=roundddef||rnds.crond
  960.          if pos(currond,lines.j) > 0 then   lines.j=currond||crond
  961.          if pos(currrondn,lines.j) > 0 then do
  962.             if pos("2 Legs",rnds.crond) > 0 then
  963.                lines.j=currrondn||substr(rnds.crond,1,5)"  1 Leg"
  964.             else
  965.                lines.j=currrondn||substr(rnds.crond,1,5)
  966.          end
  967.          if pos(teams_cnt,lines.j) > 0 then lines.j=teams_cnt||winct
  968.       end
  969.       if open(datafile,league_file || input3_file,'w') then do
  970.          do j=1 to linesct
  971.             if pos(separator,lines.j) > 0 then
  972.                writeln(datafile,lines.j)
  973.          end
  974.          if pos("Third",crond) > 0 then do
  975.             writeln(datafile,"#"working.1)
  976.             writeln(datafile,"#"working.2)
  977.             writeln(datafile,losing.1)
  978.             writech(datafile,losing.2)
  979.          end
  980.          else do
  981.             do j=1 to winct
  982.                if j = winct then
  983.                   writech(datafile,working.j)
  984.                else
  985.                   writeln(datafile,working.j)
  986.             end
  987.          end
  988.          close(datafile)
  989.       end
  990.       else do
  991.          say
  992.          say csnr_error
  993.          say
  994.          say csnr_t2"'"league_file || input3_file"'"csnr_t6
  995.          exit
  996.       end
  997.       if pos("Semi",tcrondn) > 0 then do
  998.          if open(outfile,league_file || input2_file,"a") then do
  999.             if pos("YES",third) > 0 then do
  1000.                writeln(outfile,"*Round=Third")
  1001.                writeln(outfile,"*")
  1002.                writeln(outfile,left(losing.1,30)" __   __ " losing.2)
  1003.                writeln(outfile,"*")
  1004.             end
  1005.             leg_do = ""
  1006.             if pos("2 Legs",rnds.rndcnt) > 0 then
  1007.                leg_do = "1 Leg"
  1008.             writeln(outfile,"*Round=Final   "leg_do)
  1009.             writeln(outfile,"*")
  1010.             writeln(outfile,left(working.1,30)" __   __ " working.2)
  1011.             writech(outfile,"*")
  1012.             close(outfile)
  1013.          end
  1014.          else do
  1015.             say
  1016.             say csnr_error
  1017.             say
  1018.             say csnr_t9"'"league_file || input2_file"'."
  1019.             exit
  1020.          end
  1021.          leg_do = "Blank"
  1022.          if pos("2 Legs",rnds.rndcnt) > 0 then
  1023.             leg_do = "1 Leg"
  1024.          say
  1025.          say center("'"cupname"'",78)
  1026.          say "-------------------------------------------------------------------------------"
  1027.          say
  1028.          say cs_t28" : "bettername("Final",leg_do)
  1029.          say
  1030.          say left(working.1,30)" "txt_versus" "working.2
  1031.          say
  1032.          say
  1033.          if pos("YES",third) > 0 then do
  1034.             say cs_t28" : "bettername("Third","Blank")
  1035.             say
  1036.             say left(losing.1,30)" "txt_versus" "losing.2
  1037.             say
  1038.          end
  1039.          say
  1040.          say "-------------------------------------------------------------------------------"
  1041.          exit
  1042.       end
  1043.  
  1044.       if pos("AUTOMATIC",scht) > 0 then do
  1045.          nums = ''
  1046.          numct= 0
  1047.          closed = winct
  1048.          rndseed= winct * rndcnt
  1049.          do while closed ~= 0
  1050.             t = random(1,closed,time('s'))
  1051.             if find(nums,t) = 0 then do
  1052.                if numct = 0 then do
  1053.                   numct = 1
  1054.                   nums  = t
  1055.                end
  1056.                else do
  1057.                   numct = numct + 1
  1058.                   nums = nums||" "||t
  1059.                end
  1060.             end
  1061.             if numct = winct-1 then do
  1062.                do f=1 to winct
  1063.                   if pos(f,nums) = 0 then
  1064.                      nums = nums||" "f
  1065.                end
  1066.                numct = numct + 1
  1067.                closed = 0
  1068.             end
  1069.          end
  1070.       end
  1071.       if open(outfile,league_file || input2_file,"a") then do
  1072.          leg_do = ""
  1073.          if pos("2 Legs",rnds.crond) > 0 then
  1074.             leg_do = "1 Leg"
  1075.          writeln(outfile,"*Round="word(rnds.crond,1)"   "leg_do)
  1076.          writeln(outfile,"*")
  1077.          if pos("AUTOMATIC",scht) > 0 then do
  1078.             home = 0
  1079.             away = 0
  1080.             do i=1 to winct by 2
  1081.                home = word(nums,i)
  1082.                away = word(nums,i+1)
  1083.                writeln(outfile,left(working.home,30)" __   __ " working.away)
  1084.             end
  1085.             writeln(outfile,"*")
  1086.          end
  1087.          close(outfile)
  1088.          if pos("AUTOMATIC",scht) = 0 then do
  1089.             if open(datafile,indicator,'w') then do
  1090.                writeln(datafile,"Matches To Be Scheduled")
  1091.                close(datafile)
  1092.             end
  1093.             else do
  1094.                say
  1095.                say csnr_error
  1096.                say
  1097.                say csnr_t17
  1098.                say csnr_t18
  1099.                exit
  1100.             end
  1101.          end
  1102.       end
  1103.       else do
  1104.          say
  1105.          say csnr_error
  1106.          say
  1107.          say csnr_t9"'"league_file || input2_file"'."
  1108.          exit
  1109.       end
  1110.       leg_do = "Blank"
  1111.       if pos("2 Legs",rnds.crond) > 0 then
  1112.          leg_do = "1 Leg"
  1113.       say
  1114.       say center("'"cupname"'",78)
  1115.       say "-------------------------------------------------------------------------------"
  1116.       say
  1117.       say cs_t28" : "bettername(substr(rnds.crond,1,5),leg_do)
  1118.       say
  1119.       say csnr_t19
  1120.       say
  1121.       if pos("AUTOMATIC",scht) > 0 then do
  1122.          do i=1 to winct by 2
  1123.             home = word(nums,i)
  1124.             away = word(nums,i+1)
  1125.             say left(working.home,30)" "txt_versus" "working.away
  1126.          end
  1127.          say
  1128.          say "-------------------------------------------------------------------------------"
  1129.       end
  1130.       exit
  1131.    end
  1132. end
  1133.  
  1134. exit
  1135.  
  1136. /* Routine ----------------------------------------------------------- */
  1137.  
  1138. whosthewinr:
  1139. parse arg start,rdef,wroundname,num_leg,gls_away
  1140.  
  1141. et   = 0
  1142. pe   = 0
  1143. etr  = 0
  1144. per  = 0
  1145. spos = start
  1146. fchk = 0
  1147.  
  1148. if pos("Replay",wroundname) = 0 then do
  1149.    if pos("Extra Time",rdef) > 0 then et = 2
  1150.    if pos("Penalties",rdef) > 0 then  pe = 2
  1151.    if pos("2 Legs",rdef) > 0 & num_leg = 1 then do
  1152.       teama = strip(substr(matches.spos,1,30))
  1153.       teamb = strip(substr(matches.spos,41,30))
  1154.       return teama"#####"teamb
  1155.    end
  1156.    teama = strip(substr(matches.spos,1,30))
  1157.    teamb = strip(substr(matches.spos,41,30))
  1158.    form = strip(substr(matches.spos,32,2))
  1159.    agam = strip(substr(matches.spos,37,2))
  1160.    if pos("2 Legs",rdef) > 0 & num_leg = 2 then do
  1161.       spos = spos + 1
  1162.       for1l = strip(substr(matches.spos,32,2))
  1163.       aga1l = strip(substr(matches.spos,37,2))
  1164.       if for1l = '' | aga1l = '' then return "NOP"
  1165.       for = form + for1l
  1166.       aga = agam + aga1l
  1167.    end
  1168.    else do
  1169.       for = form
  1170.       aga = agam
  1171.    end
  1172.    if for > aga then do
  1173.       return teama"*****"teamb
  1174.    end
  1175.    if for < aga then do
  1176.       return teamb"*****"teama
  1177.    end
  1178.    if num_leg = 2 & pos("YES",gls_away) > 0 then do
  1179.       if for = aga then do
  1180.          if for1l > agam then return teama"*****"teamb
  1181.          if for1l < agam then return teamb"*****"teama
  1182.       end
  1183.    end
  1184.    if for = aga & et = 2 then do
  1185.       spos = spos + 1
  1186.       for1 = strip(substr(matches.spos,32,2))
  1187.       aga1 = strip(substr(matches.spos,37,2))
  1188.       if pos("2 Legs",rdef) > 0 & num_leg = 2 then do
  1189.          f1 = for1 + for1l
  1190.          a1 = aga1 + aga1l
  1191.          if f1 > a1 then return teama"*****"teamb
  1192.          if f1 < a1 then return teamb"*****"teama
  1193.          if f1 = a1 then do
  1194.             if pos("YES",gls_away) > 0 then do
  1195.                if for1l > aga1 then return teama"*****"teamb
  1196.                if for1l < aga1 then return teamb"*****"teama
  1197.                if for1l = aga1 then do
  1198.                   if for1 = for1l & aga1 = aga1l then
  1199.                      for1 = aga1
  1200.                   else do
  1201.                      if aga1 > for1l then return teamb"*****"teama
  1202.                      if aga1 < for1l then return teama"*****"teamb
  1203.                      if aga1 = for1l then for1 = aga1
  1204.                   end
  1205.                end
  1206.             end
  1207.             else
  1208.                for1 = aga1    /* to force penalties when ET after 2 legs */
  1209.          end
  1210.       end
  1211.       if for1 > aga1 then return teama"*****"teamb
  1212.       if for1 < aga1 then return teamb"*****"teama
  1213.       if for1 = aga1 & pe = 2 then do
  1214.          spos = spos + 1
  1215.          for2 = strip(substr(matches.spos,32,2))
  1216.          aga2 = strip(substr(matches.spos,37,2))
  1217.          if for2 > aga2 then return teama"*****"teamb
  1218.          if for2 < aga2 then return teamb"*****"teama
  1219.          if for2 = aga2 then do
  1220.             repct = repct + 1
  1221.             replays.repct = matches.start
  1222.             return "REPLAY"
  1223.          end
  1224.       end
  1225.       else do
  1226.          repct = repct + 1
  1227.          replays.repct = matches.start
  1228.          return "REPLAY"
  1229.       end
  1230.    end
  1231.    if for = aga & pe = 2 & et = 0 then do
  1232.       spos = spos + 1
  1233.       for1 = strip(substr(matches.spos,32,2))
  1234.       aga1 = strip(substr(matches.spos,37,2))
  1235.       if for1 > aga1 then return teama"*****"teamb
  1236.       if for1 < aga1 then return teamb"*****"teama
  1237.       if for1 = aga1 then do
  1238.          repct = repct + 1
  1239.          replays.repct = matches.start
  1240.          return "REPLAY"
  1241.       end
  1242.    end
  1243.    if for = aga & pe = 0 & et = 0 then do
  1244.       repct = repct + 1
  1245.       replays.repct = matches.start
  1246.       return "REPLAY"
  1247.    end
  1248. end
  1249.  
  1250. spos = start
  1251. if pos("Replay",wroundname) > 0 then do
  1252.    if pos("Extra Time",rdef) > 0 then   et  = 2
  1253.    if pos("E.T If Rep.",rdef) > 0 then  etr = 2
  1254.    if pos("Penalties",rdef) > 0 then    pe  = 2
  1255.    if pos("Pen If Rep.",rdef) > 0 then  per = 2
  1256.  
  1257.    teama = strip(substr(matches.spos,1,30))
  1258.    teamb = strip(substr(matches.spos,41,30))
  1259.    for = strip(substr(matches.spos,32,2))
  1260.    aga = strip(substr(matches.spos,37,2))
  1261.    if for > aga then return teama"*****"teamb
  1262.    if for < aga then return teamb"*****"teama
  1263.    if for = aga & (etr = 2 | et = 2) then do
  1264.       spos = spos + 1
  1265.       for1 = 0
  1266.       aga1 = 0
  1267.       for1 = strip(substr(matches.spos,32,2))
  1268.       aga1 = strip(substr(matches.spos,37,2))
  1269.       if for1 > aga1 then return teama"*****"teamb
  1270.       if for1 < aga1 then return teamb"*****"teama
  1271.       if for1 = aga1 & (per = 2 | pe = 2) then do
  1272.          spos = spos + 1
  1273.          for2 = strip(substr(matches.spos,32,2))
  1274.          aga2 = strip(substr(matches.spos,37,2))
  1275.          if for2 > aga2 then return teama"*****"teamb
  1276.          if for2 < aga2 then return teamb"*****"teama
  1277.          if for2 = aga2 then do
  1278.             repct = repct + 1
  1279.             replays.repct = matches.start
  1280.             return "REPLAY"
  1281.          end
  1282.       end
  1283.       else do
  1284.          repct = repct + 1
  1285.          replays.repct = matches.start
  1286.          return "REPLAY"
  1287.       end
  1288.    end
  1289.    if for = aga & per = 2 & et = 0 & etr = 0 then do
  1290.       spos = spos + 1
  1291.       for1 = strip(substr(matches.spos,32,2))
  1292.       aga1 = strip(substr(matches.spos,37,2))
  1293.       if for1 > aga1 then return teama"*****"teamb
  1294.       if for1 < aga1 then return teamb"*****"teama
  1295.       if for1 = aga1 then do
  1296.          repct = repct + 1
  1297.          replays.repct = matches.start
  1298.          return "REPLAY"
  1299.       end
  1300.    end
  1301.    if for = aga & pe = 0 & et = 0 & etr = 0 & per = 0 then do
  1302.       repct = repct + 1
  1303.       replays.repct = matches.start
  1304.       return "REPLAY"
  1305.    end
  1306. end
  1307.  
  1308. return "NOP"
  1309.  
  1310. /* Routine ----------------------------------------------------------- */
  1311.  
  1312. bettername:
  1313. parse arg crn,legless
  1314.  
  1315. trdn = substr(crn,1,1)
  1316. if datatype(trdn,'n') = 1 then do
  1317.    if pos("Replay",crn) > 0 then
  1318.       trn = strip(word(crn,1))" "cs_t28" "cs_t31
  1319.    else do
  1320.       parse var crn roundno" " .
  1321.       trn = strip(crn)" "cs_t28
  1322.    end
  1323. end
  1324. else do
  1325.    if pos("Final",crn) > 0 then do
  1326.       if pos("Replay",crn) > 0 then
  1327.          trn = cs_t30" "cs_t31
  1328.       else
  1329.          trn = cs_t30
  1330.    end
  1331.    if pos("Semi",crn) > 0 then do
  1332.       if pos("Replay",crn) > 0 then
  1333.          trn = cs_t32" "cs_t31
  1334.       else
  1335.          trn = cs_t33
  1336.    end
  1337.    if pos("Quart",crn) > 0 then do
  1338.       if pos("Replay",crn) > 0 then
  1339.          trn = cs_t34" "cs_t31
  1340.       else
  1341.          trn = cs_t35
  1342.    end
  1343.    if pos("Third",crn) > 0 then do
  1344.       trn = cs_t36
  1345.    end
  1346. end
  1347.  
  1348. if pos("1 Leg",legless) > 0 then
  1349.    trn = trn"  ("cum_t32")"
  1350. if pos("2 Legs",legless) > 0 then
  1351.    trn = trn"  ("cum_t33")"
  1352.  
  1353. return trn
  1354.  
  1355. /* ------------------------------------------------------------------- */